package com.czk.yygh.cmn.listen;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.czk.model.cmn.Dict;
import com.czk.vo.cmn.DictEeVo;
import com.czk.yygh.cmn.mapper.DictMapper;
import org.springframework.beans.BeanUtils;

/**
 * easyExcel读写监听器
 *
 * @Author:ChenZhangKun
 * @Date: 2021/11/7 17:05
 */
public class ExcelDictListener extends AnalysisEventListener<DictEeVo> {
    private DictMapper dictMapper;

    /**
     * 通过构造器注入
     *
     * @param dictMapper
     */
    public ExcelDictListener(DictMapper dictMapper) {
        this.dictMapper = dictMapper;
    }

    @Override
    public void invoke(DictEeVo dictEeVo, AnalysisContext analysisContext) {
        // 调用方法注入数据库
        Dict dict = new Dict();
        // 拷贝属性
        BeanUtils.copyProperties(dictEeVo, dict);
        // 出入数据库
        dictMapper.insert(dict);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
